<?php

class Involved_NewsModel extends BaseModel
{

    protected $table = 'news';

    /**
     *资讯列表
     * @return mixed
     * $type 咨询类型 $t新闻条数
     */
    public function NewsIndexSelect($type,$t=null)
    {
        if($t){
            return DB::table($this->table)
                ->select('news_id','title','content','type','created','status','author','img','source')
                ->where('type',$type)
                ->orderBy('created', 'desc')
                ->skip(0)->take($t)
                ->get();
        }else{
            return DB::table($this->table)
                ->select('news_id','title','content','type','created','status','author','img','source')
                ->where('type',$type)
                ->orderBy('created', 'desc')
                ->get();
        }

    }

    /**
     * 公告查询
     * $type
     */
    public function AnnouncementListSelect($type,$t=null){
        if($t){
            return DB::table($this->table)
                ->select('news_id','title','type','created')
                ->where('type',$type)
                ->orderBy('created', 'desc')
                ->skip(0)->take($t)
                ->get();
        }else{
            return DB::table($this->table)
                ->select('news_id','title','type','created')
                ->where('type',$type)
                ->orderBy('created', 'desc')
                ->get();
        }
    }


    public function GetNewsId($news_id)
    {
        return DB::table($this->table)
            ->select('news_id','title','content','type','created','status','author','img','source')
            ->where('news_id',$news_id)
            ->first();
    }

    #关于我们-咨询中心
    /**+
     * 行业资讯
     * @return mixed
     */
    public function AboutInfo1()
    {
        return DB::table($this->table)
            ->select('news_id','title','content','status','created','type','author','img','source')
            ->where('type',1)
            ->get();

    }

    /**
     * 行业资讯分页
     * @param $page
     * @return mixed
     */
    public function AboutInfo1Page1($page)
    {
        $limit = ($page-1)*5;
        return DB::table($this->table)
        ->select('news_id','title','content','status','created','type','author','img','source')
            ->where('type',1)
            ->skip($limit)->take(5)
             ->get();
    }

    /**
     * 平台新闻
     * @return mixed
     */
    public function AboutInfo2()
    {
        return DB::table($this->table)
            ->select('news_id','title','content','status','created','type','author','img','source')
            ->where('type',2)
            ->get();

    }

    /**
     * 平台新闻分页
     * @param $page
     * @return mixed
     */
    public function AboutInfo1Page2($page)
    {
        $limit = ($page-1)*5;
        return DB::table($this->table)
            ->select('news_id','title','content','status','created','type','author','img','source')
            ->where('type',2)
            ->skip($limit)->take(5)
            ->get();
    }

    /**
     * 媒体报道
     * @return mixed
     */
    public function AboutInfo3()
    {
        return DB::table($this->table)
            ->select('news_id','title','content','status','created','type','author','img','source')
            ->where('type',3)
            ->get();
    }

    /**
     * 媒体报道分页
     * @param $page
     * @return mixed
     */
    public function AboutInfo1Page3($page)
    {
        $limit = ($page-1)*5;
        return DB::table($this->table)
            ->select('news_id','title','content','status','created','type','author','img','source')
            ->where('type',3)
            ->skip($limit)->take(5)
            ->get();
    }

    public function AboutInfoContent($news_id)
    {
        return DB::table($this->table)
            ->select('news_id','title','content','status','created','type','author','img','source')
            ->where('news_id',$news_id)
            ->first();
    }
}
